<?php namespace Home\Controller; 

use Hdphp\Controller\Controller;

//测试控制器
class ImagesController extends Controller{
	private $model;
	
	public function __init(){
	  	$this->model=new \Common\Model\Homeuser;
	}
	
	public function index(){
		//获得当前的用户id
		$uid=$_SESSION['uid'];
		$homeuser=$this->model->where('uid='.$uid)->find();
		
	View::with('homeuser',$homeuser);
//	p($homeuser);	
		//这里因为form表单提交不到edit方法所以只能在这里做啦
		if(IS_POST){
			$this->edit(Q('post.'));
		}
	
	    View::make();
	}
	
	//异步上传一张头像
	public function personUpload(){
	
	    $file = Upload::path('Upload/Content/headimg' . date('y/m'))->make();
	    if (empty($file)) {
	        $this->ajax(Upload::getError());
	    } else {
	        /** $file内部就是以下这个数组
	            $file = array(
	                0 => array(
		                'path' => 'Upload/Content/15/8/123981239172.jpg'    ,
		                'url' => 'http://localhost/cms_edu/Upload/Content/15/8/123981239172.jpg',
		                'image' => 1
	            ),
	        );**/
	        //上传成功，把上传好的信息返给js
	        $data = $file[0];
	        echo json_encode($data);exit;
	    }
	}
	//对账户信息的修改
	public function edit($data){
		//跳转到模型来处理对应的修改数据操作
		if($this->model->edit($data))
		
		View::success('修改成功',U('images/index'));		
		
	}
	
}
